package tjs.study.notes.dotest.jdk.thread;

import java.util.concurrent.locks.LockSupport;

/**
 * Created by Nicky.Tang on 2021/11/16 3:01 下午
 *
 * @since 02.12.10
 */
public class DoTestOfLockSupport {
    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            System.out.println("t1已进入");
            LockSupport.park();// 挂起当前线程
            for (int i = 0; i <10 ; i++) {
                System.out.println("t1已启动"+i);
                try {
                    Thread.currentThread().sleep(200);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        Thread t2 = new Thread(() -> {
            System.out.println("t2已进入");
            for (int i = 0; i <10 ; i++) {
                System.out.println("t2已启动"+i);
                try {
                    Thread.currentThread().sleep(200);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            LockSupport.unpark(t1);// 唤醒目标线程
        });
        t1.start();
        t2.start();
    }
}
